package com.itheima.mylistdemo;

import java.util.LinkedList;

public class Test2 {
    public static void main(String[] args) {
        MyStack stack2=new MyStack();
        stack2.push("hello");
        stack2.push("world");
        stack2.push("java");

        //取出
        System.out.println(stack2.pop());
        System.out.println(stack2.pop());
        System.out.println(stack2.pop());

    }

}

//队列特点：先进先出
class MyStack2{
    private LinkedList<Object> stack2=new LinkedList<>();

    //存元素方法
    public void push2(Object obj2){
        stack2.addFirst(obj2);
    }

    //取元素方法
    public Object pop2(){
        return stack2.removeLast();
    }

}